/*
 * Filename AlgoRequestLog.java 2021年09月26日
 * Copyright © Ehome Co.Ltd. All Rgiths Reserved.
 * @author wuyingchao
 */
package com.ehome.poct.core.api.dto.check;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import lombok.Data;

/**
 * 算法调用日志
 *
 * @author wyc
 * @since 2021/09/26 18:06
 **/
@Data
public class AlgoRequestLog {
    private Long id;
    private final String reqUrl;
    private final String responseContent;
    private final String sno;
    private final String filePath;

    public AlgoRequestLog(Long id, String reqUrl,  String responseContent, String sno, String filePath) {
        this.id = id;
        this.sno = sno;
        this.reqUrl = reqUrl;
        this.filePath = filePath;
        this.responseContent = responseContent;
    }
    /**
     * 响应是否成功
     * <p>响应内容中的响应码是否 == 200</p>
     * @return true: 成功  false: 失败
     */
    public boolean responseIsSuccess() {
        if (StrUtil.isNotBlank(responseContent)) {
            return "200".equals(new JSONObject(responseContent).getStr("code"));
        }
        return false;
    }
}